#(1)Local
#Local path
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) 
Local := $(dir $(mkfile_path))

#(2)Compiler
##GCC
GCC = gcc
GCC_FLAGS = -O3 -w -lm -c -lpthread
##NVCC
NVCC = nvcc
NVCC_FLAGS = -O3 -w -lm -arch=sm_60 -pg -Xcompiler -g -G -c 

#(3)CUDA
##CUDA_PATH
CUDA_INSTALL_PATH = /usr/local/cuda
##CUDA_LIB
CUDA_LIBS = -L$(CUDA_INSTALL_PATH)/lib64 -lcudart -lcusparse -lcublas -lcusolver -lcurand 
##CUDA_INCLUDE
CUDA_INCLUDE = -I$(CUDA_INSTALL_PATH)/include -I$(CUDA_INSTALL_PATH)/samples/common/inc
##CUB_PATH
# CUB_PATH = $(CUDA_INSTALL_PATH)/include/thrust/system/cuda/detail/
#CUB_PATH = $(CUDA_INSTALL_PATH)/targets/x86_64-linux/include/thrust/system/cuda/detail
#CUB_PATH = /usr/include/thrust/system/cuda/detail/

#(4)EXTERNAL
##NSPARSE
NSPARSE_INCLUDE = -I$(Local)/External/nsparse/cuda-c/inc/ -DDOUBLE
NSPARSE_OBJ = $(Local)/External/nsparse/cuda-c/obj/
NSPARSE_conversion_OBJ = $(Local)/External/nsparse/cuda-c/obj/conversion/
NSPARSE_kernel_OBJ = $(Local)/External/nsparse/cuda-c/obj/kernel/

##CSR5_PARAMETERS
VALUE_TYPE = double
CSR5_FLAGS = -m64 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_60,code=compute_60 -Xcompiler -fpermissive

##METIS
METIS_INCLUDE = -I/usr/local/include
METIS_LIBS = -L/usr/local/lib -lmetis

##GMETIS
# GMETIS_LIBS = -L/home/txt/TXT_AMG/GPU/v4.18 libggp.a 
# GMETIS_INCLUDE =-I/home/txt/TXT_AMG/GPU/v4.18/gmetis

#tree
Main = Main/src/
Setup = Setup/src/
Solve = Solve/src/
Gmetis = gmetis/
Out = out/

make:
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Main)SSS_main.cu
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Main)SSS_AMG.cu
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Main)SSS_matvec.cu
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Main)SSS_utils.cu

	# $(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) --expt-relaxed-constexpr $(Gmetis)ggp.cu
	# ar cr libggp.a ggp.o


	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Setup)SSS_soc.cu
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(METIS_LIBS) $(METIS_INCLUDE) --expt-relaxed-constexpr  $(Setup)SSS_coarsen.cu 
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(NSPARSE_INCLUDE) $(NSPARSE_OBJ)nsparse.d.o $(NSPARSE_kernel_OBJ)kernel_spgemm_cu_csr.d.o $(NSPARSE_kernel_OBJ)kernel_spgemm_hash_d.d.o  $(Setup)SSS_SETUP.cu 
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Setup)SSS_inter.cu

	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(NSPARSE_INCLUDE) $(NSPARSE_OBJ)nsparse.d.o $(NSPARSE_conversion_OBJ)convert_amb.d.o $(NSPARSE_kernel_OBJ)kernel_spmv_amb.d.o -D VALUE_TYPE=$(VALUE_TYPE) $(Solve)SSS_SOLVE.cu
	$(NVCC) $(NVCC_FLAGS) $(CSR5_FLAGS) $(NSPARSE_INCLUDE) $(NSPARSE_OBJ)nsparse.d.o $(NSPARSE_conversion_OBJ)convert_amb.d.o $(NSPARSE_kernel_OBJ)kernel_spmv_amb.d.o $(CUDA_LIBS) $(CUDA_INCLUDE) $(CSR5_INCLUDES) -D VALUE_TYPE=$(VALUE_TYPE) $(Solve)SSS_cycle.cu
	$(NVCC) $(NVCC_FLAGS) $(CUDA_LIBS) $(CUDA_INCLUDE) $(Solve)SSS_smooth.cu
	

	mv *.o $(Out)

	$(NVCC) -Xcompiler -fopenmp -w -g -G -pg -arch=sm_60 -o amg $(NSPARSE_OBJ)nsparse.d.o $(NSPARSE_kernel_OBJ)kernel_spgemm_cu_csr.d.o $(NSPARSE_kernel_OBJ)kernel_spgemm_hash_d.d.o  $(NSPARSE_conversion_OBJ)convert_amb.d.o $(NSPARSE_kernel_OBJ)kernel_spmv_amb.d.o $(Out)SSS_utils.o $(Out)SSS_matvec.o $(Out)SSS_soc.o $(Out)SSS_inter.o  $(Out)SSS_coarsen.o  $(Out)SSS_smooth.o $(Out)SSS_cycle.o $(Out)SSS_SOLVE.o $(Out)SSS_SETUP.o  $(Out)SSS_AMG.o $(Out)SSS_main.o   -lm  $(NSPARSE_INCLUDE) $(CUDA_LIBS) $(CUDA_INCLUDE) $(METIS_LIBS) $(METIS_INCLUDE)  



